package com.imsprint.xmlldemo;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.imsprint.lib.observe.Observer;
import com.imsprint.lib.observe.ObserverManager;

public class MainActivity extends AppCompatActivity {
    TextView tv;

    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("native-lib");
    }

    /**
     * 测试6
     * @param savedInstanceState
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        // Example of a call to a native method
        tv = (TextView) findViewById(R.id.sample_text);
        tv.setText(stringFromJNI());
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, SecondActivity.class));
            }
        });
    }

    public void onRegister(View v) {
        ObserverManager.getObservableInstance().register(myObserver);
    }

    public void onunRegister(View v) {
        ObserverManager.getObservableInstance().unRegister(myObserver);
    }


    Observer<Message> myObserver = new Observer<Message>() {

        @Override
        public void onEvent(Message o) {
            Toast.makeText(MainActivity.this, o.getMsg(), Toast.LENGTH_SHORT).show();
            tv.setText(o.getMsg());
        }
    };


    /**
     * 002
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
    public native String stringFromJNI();
}
